package com.workstudy.wstudy.controller;

import java.util.List;

import com.workstudy.common.core.domain.entity.SysUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.workstudy.common.annotation.Log;
import com.workstudy.common.enums.BusinessType;
import com.workstudy.wstudy.domain.WstPostFinished;
import com.workstudy.wstudy.service.IWstPostFinishedService;
import com.workstudy.common.core.controller.BaseController;
import com.workstudy.common.core.domain.AjaxResult;
import com.workstudy.common.utils.poi.ExcelUtil;
import com.workstudy.common.core.page.TableDataInfo;

/**
 * 往期岗位Controller
 * 
 * @author sun
 * @date 2021-04-07
 */
@Controller
@RequestMapping("/wstudy/finished")
public class WstPostFinishedController extends BaseController
{
    private String prefix = "wstudy/finished";

    @Autowired
    private IWstPostFinishedService wstPostFinishedService;

    @RequiresPermissions("wstudy:finished:view")
    @GetMapping()
    public String finished(ModelMap modelMap)
    {
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        modelMap.put("user",user);
        return prefix + "/finished";
    }

    /**
     * 查询往期岗位列表
     */
    @RequiresPermissions("wstudy:finished:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WstPostFinished wstPostFinished)
    {
        startPage();
        List<WstPostFinished> list = wstPostFinishedService.selectWstPostFinishedList(wstPostFinished);
        return getDataTable(list);
    }

    /**
     * 导出往期岗位列表
     */
    @RequiresPermissions("wstudy:finished:export")
    @Log(title = "往期岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WstPostFinished wstPostFinished)
    {
        List<WstPostFinished> list = wstPostFinishedService.selectWstPostFinishedList(wstPostFinished);
        ExcelUtil<WstPostFinished> util = new ExcelUtil<WstPostFinished>(WstPostFinished.class);
        return util.exportExcel(list, "finished");
    }

    /**
     * 新增往期岗位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存往期岗位
     */
    @RequiresPermissions("wstudy:finished:add")
    @Log(title = "往期岗位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WstPostFinished wstPostFinished)
    {
        return toAjax(wstPostFinishedService.insertWstPostFinished(wstPostFinished));
    }

    /**
     * 修改往期岗位
     */
    @GetMapping("/edit/{postId}")
    public String edit(@PathVariable("postId") Long postId, ModelMap mmap)
    {
        WstPostFinished wstPostFinished = wstPostFinishedService.selectWstPostFinishedById(postId);
        mmap.put("wstPostFinished", wstPostFinished);
        return prefix + "/edit";
    }

    /**
     * 往期岗位详情
     */
    @GetMapping("/details/{postId}")
    public String details(@PathVariable("postId") Long postId, ModelMap mmap)
    {
        WstPostFinished wstPostFinished = wstPostFinishedService.selectWstPostFinishedById(postId);
        mmap.put("wstPostFinished", wstPostFinished);
        return prefix + "/details";
    }

    /**
     * 修改保存往期岗位
     */
    @RequiresPermissions("wstudy:finished:edit")
    @Log(title = "往期岗位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WstPostFinished wstPostFinished)
    {
        return toAjax(wstPostFinishedService.updateWstPostFinished(wstPostFinished));
    }

    /**
     * 删除往期岗位
     */
    @RequiresPermissions("wstudy:finished:remove")
    @Log(title = "往期岗位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wstPostFinishedService.deleteWstPostFinishedByIds(ids));
    }
}
